

export default {
    data: {
        merchant$: '',
    },
    handleMerchantNext (item, type = false) {
        let { params$ } = this.data;
        let { category, steps, index = 0, storeId = '' } = item || params$ || {};
        let objStep = steps[index];
        if (!objStep) {
            return this.routerPush('merchant_status_index', (item || params$ || {}));
        }
        index++;
        this.routerPush(objStep.url, { category, steps, index, storeId }, type);
    },
    reqMerchantInfo (key, loading = true) {
        let { api$ } = this.data;
        this.httpRequest(api$.REQ_MERCHANT_INFO, {}, {
            loading,
        }).then((res) => {
            let merchant$ = res || {};
            this.setData({ merchant$ });
            this.assignmentData(key, merchant$)
        }).toast();
    },
    assignmentData (key, source) {
        if (!key) return null;
        let data = source[key];
        if (!data) return null;
        if (key === 'mainInfo') {
            let { licenseStartDate, licenseExpiryDate } = data;
            if (licenseStartDate) {
                data.licenseStartDate = `${licenseStartDate.substring(0, 4)}-${licenseStartDate.substring(4, 6)}-${licenseStartDate.substring(6)}`;
            }
            if (licenseExpiryDate) {
                data.licenseExpiryDate = `${licenseExpiryDate.substring(0, 4)}-${licenseExpiryDate.substring(4, 6)}-${licenseExpiryDate.substring(6)}`;
            }
        }
        let { objInput, objHidden } = this.data;
        if (objInput) {
            this.validateAssignment(this, data, objInput, 'objInput');
        }
        if (objHidden) {
            this.validateAssignment(this, data, objHidden, 'objHidden');
        }
    },
}
